package com.itheima.controller.sms;

import com.itheima.core.PageInfo;
import com.itheima.core.R;
import com.itheima.pojo.sms.SmsFlashPromotionProductRelation;
import com.itheima.service.sms.SmsFlashPromotionProductRelationService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

    @RestController
    @RequestMapping("/flashProductRelation")
 public class SmsFlashPromotionProductRelationController {
        @DubboReference
    private SmsFlashPromotionProductRelationService sFPPtRService;
    /*批量选择商品添加关联*/
    @PostMapping("/create")
    public R create(@RequestBody  List<SmsFlashPromotionProductRelation> smsFlashPromotionProductRelations){
        sFPPtRService.create(smsFlashPromotionProductRelations);
        return R.success();
    }

    /*删除关联*/
    @PostMapping("/delete/{id}")
    public R deleteBYid(@RequestParam int id){
    sFPPtRService.removeById(id);
    return R.success();
    }


    /*分页查询不同场次关联及商品信息*/
        @GetMapping("/list")
        public R listall(Integer flashPromotionId,Integer flashPromotionSessionId,Integer pageNum,Integer pageSize){
             PageInfo info= sFPPtRService.listAll(flashPromotionId,flashPromotionSessionId,pageNum,pageSize);

            return R.success();
        }


        /*修改关联信息*/
        @PostMapping("/update/{id}")
        public R updateById(@RequestBody  SmsFlashPromotionProductRelation smsFlashPromotionProductRelations){
            sFPPtRService.updateBy(smsFlashPromotionProductRelations);
            return  R.success();
        }

        /*获取管理商品促销信息*/
        @GetMapping("{id}")
        public R geiByid(@RequestParam int id){
            SmsFlashPromotionProductRelation byId = sFPPtRService.getById(id);
            return R.success("",byId);
        }
}
